<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        <title>test-service</title>
        <script type="text/javascript" src="http://samples.localhost/jquery/jquery-1.5.min.js"></script>
        <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.0/jquery.min.js"></script>
    </head>
    <body>
        Url: <input type="text" id="url" value="/service/account/login" style="width: 255px" />
        Accept: <select id="format" style="width: 50px">
            <option value="application/json">json</option>
            <option value="application/xml">xml</option>
        </select>
        AuthToken: <input type="text" id="authToken" value="" style="width: 100px" />
        <button id="button">Send request!</button>
        <br />
        <textarea id="params" style="width: 700px; height: 200px;"></textarea>
        <hr />
        
        Actions:
        <br />

        <strong>Account: </strong>
        <button id="login">Login</button>
        <button id="userInfo">User info</button>
        <button id="logout">Logout</button>
        <button id="register">Register</button>
        <button id="updateProfile">Update profile</button>
        <br />

        <strong>Trip: </strong>
        <button id="filter">Filter trips</button>
        <button id="create">Create new trip</button>
        <button id="createTripRequest">Apply for a seat in trip</button>
        |
        <button id="usersInTrip">Get requests [DRIVE ONLY]</button>
        <button id="confirmTripRequest">Confirm request [DRIVE ONLY]</button>
        <button id="rejectTripRequest">Reject request [DRIVE ONLY]</button>
        <br />

        <strong>Message: </strong>
        <button id="getMyMessages">Get my messages</button>
        <button id="filterMyMessages">Filter my messages</button>
        <button id="sendMessage">Send message</button>

        <p id="p"></p>

        <script type="text/javascript">

function registerButton(selector, params, url, method) {
    $(selector).click(function() {
        $("#params").val(params);
        $("#url").val(url);
        $("#method").val(method);
        window.location.hash = selector;
    });
}

$(function() {
    if(window.location.hash.length > 0) {
        $(window.location.hash).click();
    }
});

$('#button').click(function() {
    $.ajax({
        type: 'POST',
        url: $('#url').val(),
        data: $('#params').val(),
        cache: false,
        beforeSend: function(xmlHttpRequest) {
          xmlHttpRequest.setRequestHeader('Accept', $('#format').val());
          var token = $('#authToken').val();
          if(token != "") {
            xmlHttpRequest.setRequestHeader('AuthToken', token);
          }
        },
        success: function(data) {
            console.log(eval(data));
        }
    });
});

registerButton(
    "#login",
    "<user-login>\n  <phone-number>606111222</phone-number>\n  <password>doe</password>\n</user-login>",
    "/service/account/login",
    ""
)
registerButton(
    "#login",
    "<user-login>\n  <phone-number>606111222</phone-number>\n  <password>doe</password>\n</user-login>",
    "/service/account/login",
    ""
);
registerButton(
    "#userInfo",
    "",
    "/service/account/info",
    ""
);
registerButton(
    "#logout",
    "",
    "/service/account/logout",
    ""
);
registerButton(
    "#register",
    "<user-update>\n  <phone-number>606111222</phone-number>\n  <password>doe</password>\n  <email>john@doe.eu</email>\n  <firstname>John</firstname>\n  <lastname>Doe</lastname>\n  <address>Dlouhá 5, Strakonice</address>\n  <car-description>Bíla škoda 120</car-description>\n</user-update>",
    "/service/account/register",
    ""
);
registerButton(
    "#updateProfile",
    "<user-update>\n  <phone-number>606111222</phone-number>\n  <password>doe</password>\n  <email>john@doe.eu</email>\n  <firstname>John</firstname>\n  <lastname>Doe</lastname>\n  <address>Dlouhá 5, Strakonice</address>\n  <car-description>Bíla škoda 120</car-description>\n</user-update>",
    "/service/account/update",
    ""
);
registerButton(
    "#getMyMessages",
    "",
    "/service/message",
    ""
);
registerButton(
    "#filterMyMessages",
    "<message-filter>\n  <count>10</count>\n  <only-unread>false</only-unread>\n  <from-user-id>SOME_USER_ID</from-user-id>\n</message-filter>",
    "/service/message",
    ""
);
registerButton(
    "#sendMessage",
    "<user-message>\n  <user-id>TARGET_USER_ID</user-id>\n  <subject>Hello Message!</subject>\n  <content>Hey, how are you?</content>\n</user-message>",
    "/service/message/send",
    ""
);
registerButton(
    "#filter",
    "<trip-filter>\n    <from>Louny</from>\n    <to>Praha</to>\n    <max-price>500</max-price>\n    <seats>2</seats>\n    <min-rating>100</min-rating>\n</trip-filter>",
    "/service/trip",
    ""
);
registerButton(
    "#create",
    "<new-trip>\n    <from>Louny</from>\n    <to>Praha</to>\n    <departure>2012-06-15</departure>\n    <arrival>2012-06-15</arrival>\n    <total-price>500</total-price>\n    <available-seats>4</available-seats>\n    <total-seats>5</total-seats>\n    <stops>\n        <trip-stop>\n            <place>Roudnice</place>\n            <arrival>2012-06-15</arrival>\n        </trip-stop>\n    </stops>\n</new-trip>",
    "/service/trip/create",
    ""
);
registerButton(
    "#createTripRequest",
    "<trip-user-request>\n    <trip-id>TRIP_ID</trip-id>\n</trip-user-request>",
    "/service/trip/request-user-to-trip",
    ""
);
registerButton(
    "#confirmTripRequest",
    "<trip-user-request>\n    <trip-id>TRIP_ID</trip-id>\n    <user-id>USER_ID</user-id>\n</trip-user-request>",
    "/service/trip/confirm-user-in-trip",
    ""
);
registerButton(
    "#rejectTripRequest",
    "<trip-user-request>\n    <trip-id>TRIP_ID</trip-id>\n    <user-id>USER_ID</user-id>\n</trip-user-request>",
    "/service/trip/remove-user-from-trip",
    ""
);
registerButton(
    "#usersInTrip",
    "<users-in-trip-filter>\n    <without-requests>OPTIONAL_TRUE_FALSE</without-requests>\n    <trip-id>TRIP_ID</trip-id>\n</users-in-trip-filter>",
    "/service/trip/users-in-trip",
    ""
);

        </script>
    </body>
</html>


